home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / basic2 / pro15 / typer.bas < prev    next >
BASIC Source File  |  1987-10-11  |  3KB  |  109 lines

  1. '*****************************************************************************
  2.  
  3. 'Copyright (c) 1987 Marcel Madonna
  4.  
  5. 'TYPER.BAS is an example of redirection.  To compile it, at the DOS prompt
  6. '       type:
  7.  
  8. '               qb typer /l qbdos.exe;
  9. '               link typer;
  10. '               del typer.obj
  11.  
  12. 'To execute TYPER just type "TYPER" at the DOS prompt and you will be prompted
  13. 'for a file name to type on the monitor.  This is a pretty simple program so
  14. '
  15. '               USE A REAL FILE NAME OR ELSE THIS PROGRAM WILL ABORT
  16. '               USE AN ASCII FILE (LICENSE.DOC ON THE DISTRIBUTION DISKETTE
  17. '                       WILL WORK JUST FINE)
  18.  
  19. 'To route the output to a printer instead of the monitor, type:
  20.  
  21. '       TYPER /LPT1
  22.  
  23. 'To route output to a file, type:
  24.  
  25. '       TYPER /TEXTFILE.DAT
  26.  
  27. '*****************************************************************************
  28.  
  29. ';Usage - Call Dosred(Device%, FileSpec$, Rc%)
  30. ';       Device% 0 - Stdin
  31. ';               1 - Stdout
  32. ';               2 - Stderr (not redirectable)
  33. ';               3 - AUX (standard auuxilliary device)
  34. ';               4 - PRN (standard list device)
  35. ';       FileSpec$ - name of file or device
  36. ';               null - reset handle
  37. ';               chr$(255) - close handle and exit
  38. ';       Rc%     0 - good return
  39. ';               6 - handle already closed
  40. ';               255 - error
  41. '*****************************************************************************
  42.  
  43.     Dim In.Array$(2000)
  44.  
  45.     If Len(Command$) = 0 then
  46.         Red% = 0
  47.     Else
  48.         Red% = -1
  49.         Pipe.Char$ = Left$(Command$,1)
  50.         Red.File$ = Right$(Command$,Len(Command$)-1)
  51.         While Left$(Red.File$,1) = Space$(1)   'Remove leading blanks
  52.             Red.File$ = Right$(Red.File$,Len(Red.File$)-1)
  53.         Wend
  54.         While Right$(Red.File$,1) = Space$(1)   'Remove trailing blanks
  55.             Red.File$ = Left$(Red.File$,Len(Red.File$)-1)
  56.         Wend
  57.     End if
  58.     Print Red.file$
  59.     Locate 1,1
  60.     Print "You are being prompted for a file name."
  61.     Print "Because this is a sample program only, I need"
  62.     Print "a real file name or else this program will "
  63.     Print "ABORT.  LICENSE.TXT on the distribution diskette"
  64.     Print "will work just fine."
  65.     Print
  66.  
  67.     Line Input "Give me a file name please: ", File.Nam$
  68.     Cls
  69.  
  70.     Open File.Nam$ For Input As #1 'Open and read the entire file
  71.     While Not Eof(1)
  72.         If x% >= Ubound(In.Array$) then
  73.             Line Input #1, In.Array$(Ubound(In.Array$))
  74.         Else
  75.             x% = x% + 1
  76.             Line Input #1, In.Array$(x%)
  77.         End if
  78.     Wend
  79.     Close #1
  80.  
  81.     Stdin%   = 0
  82.     Stdout%  = 1
  83.     Stdaux%  = 3
  84.     Stdlist% = 4
  85.  
  86. ' Redirect device here
  87.  
  88.     If Red% then
  89.         Call DosRed(Stdout%, Red.File$ + chr$(0), Rc%)
  90.         If Rc% <> 0 then
  91.             Print "Error", Rc%
  92.             System
  93.         End if
  94.     End if
  95.  
  96. ' Print file here
  97. '   Use 'print' statements to print to both CON and Red.File$
  98. '   Use DosChout to print to only Red.File$
  99.  
  100.     For y% = 1 to x%
  101.         Call Doschout(In.Array$(y%)+chr$(10)+chr$(13))
  102. '                Print In.Array$(y%)
  103.     next
  104.  
  105. ' Reset device to original
  106.  
  107.     If Red% then Call Dosred(Stdout%,"",Rc%)     'Reset device
  108.  
  109.